from django.shortcuts import render
from django.http import HttpResponse

from natp_server.models import Position, Vector, Ident, Probe

def update(request):
    
    pass

def delete(request):
    
    pass

def index(request):
    errors = []
    if 'q' in request.GET:
        q = request.GET['q']
        if not q:
            errors.append('Enter a search term.')
        elif len(q) > 20: 
            errors.append('Please enter at most 20 characters.')
        else:
            probes = Probe.objects.filter(province__icontains=q)
            return render(request, 'search_results.html', {'books':probes, 'query':q})
    return render(request, 'search_form.html', {'errors':errors})
